<template>
	<view>
		<view class="nav-chuli">
			<view class="uni-flex">
				<view>退单人员：</view>
				<view>{{ list.rebackUser }}</view>
			</view>

			<view class="uni-flex">
				<view>退单时间：</view>
				<view>{{ list.rebackTime }}</view>
			</view>
			
			<view class="uni-flex" v-if="deptKey!='chuli'&&deptKey!='shuiwu'">
				<view>处理意见：</view>
				<input type="text" v-model="handleOpinion" placeholder="请输入" />
			</view>
			
			<view class="uni-flex" v-if="deptKey=='shuiwu'">
				<view>处理意见：</view>
				<input type="text" v-model="waterOpinion" placeholder="请输入" />
			</view> 

			<view class="uni-flex">
				<view>退回原因：</view>
				<input type="text" v-model="rebackRemark" placeholder="请输入" />
			</view>
			<view class="uni-flex" @click="uploading()">
				<view>退回附件：</view>
				<view v-if="rebackFu">{{rebackFu}}</view>
				<view v-else>上传附件</view>
			</view>
		</view>

		<view class="submit" @click="submit()">确认</view>
	</view>
</template>

<script>
export default {
	data() {
		return {
			list:[],
			orderID: '',
			deptKey: '',
		
			rebackRemark: '', //退回原因
			rebackFu: '', //附件
			
			handleOpinion: '' ,//办公室退回
			
			waterOpinion: '' //水务处理意见
		};
	},
	onLoad(e) {
		this.orderID = e.orderID;
		this.deptKey = e.deptKey;
		this.list = JSON.parse(e.list)
		// console.log(this.list)
		
		this.rebackRemark = this.list.rebackRemark
		this.rebackFu = this.list.rebackFu
		
		// // 水务
		this.waterOpinion = this.list.waterOpinion 
		this.handleOpinion = this.list.handleOpinion
		
		if (this.deptKey == 'liqun' || this.deptKey == 'kuncheng' || this.deptKey == 'wushui' || this.deptKey == 'zilaishui') {
			this.leibie();
		}
	},
	methods: {
		// 下面的是上传照片
		uploading() {
			let that = this;
			uni.chooseImage({
				count: 1, //默认9
				sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
				sourceType: ["camera", "album"], //从相册选择
				success: function(res) {
					let file = res.tempFilePaths[0];
					// 下面是临时使用的方法
					// let file = res.tempFiles[0].path;
					uni.showLoading({
						mask: false
					});
					uni.uploadFile({
						url: '/app/system/upload', //仅为示例，非真实的接口地址
						filePath: file,
						name: 'file',
						success: uploadFileRes => {
							uni.hideLoading();
							const res = JSON.parse(uploadFileRes.data);
							// console.log(res)
							uni.showToast({
								title: res.message,
								icon: 'none'
							});
							// that.handleFu = file;
							that.rebackFu = res.data.fileId;
							// console.log(that.handleFu, '这是图片文件id');
						}
					});
				}
			});
		},
		// 办公室的反应类别
		leibie() {
			var that = this;
			uni.request({
				url: '/app/wechatApi/wechatOneFiveOrder/getDictsRelectWe',
				method: 'get',
				data: {
					code: 'oneFiveOrderReflectCate',
					openid: uni.getStorageSync('openid')
				},
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					if (res.data.code === 200) {
						that.array2 = res.data.data;
						// console.log(res.data.data)
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		},

		// 退回
		submit() {
			var that = this;
			if(!that.rebackRemark){
				uni.showToast({
					title:'请输入退回原因',
					icon:'none',
					duration:1500
				})
				return
			}
			var values;
			if (this.deptKey == 'chuli') {
				values = {
					orderId: this.orderID,
					openid: uni.getStorageSync('openid'),
					handlePoint: 'back',
					rebackRemark: that.rebackRemark,
					rebackFu: that.rebackFu ,
				};
			} else if (this.deptKey == 'shuiwu') {
				if(this.list.oneFiveOrderStatus == '派发_协同(a)/督查中心(a)'){
					uni.showToast({
						title:'您处理的工单为派发_协同(a)/督查中心(a)。不能驳回，请做办结处理!',
						icon:'none',
						duration:2000
					})
					return
				}
				values = {
					orderId: this.orderID,
					openid: uni.getStorageSync('openid'),
					handlePoint: 'back',
					rebackRemark: that.rebackRemark,
					rebackFu: that.rebackFu ,
					waterOpinion: that.waterOpinion,
				};
			} else if (this.deptKey == 'liqun' || this.deptKey == 'kuncheng' || this.deptKey == 'wushui' || this.deptKey == 'zilaishui') {
				values = {
					orderId: this.orderID,
					openid: uni.getStorageSync('openid'),
					handlePoint: 'back',
					rebackRemark: that.rebackRemark,
					rebackFu: that.rebackFu ,
					handleOpinion: that.handleOpinion,
				};
			}
			uni.showLoading({
				mask: false
			});
			uni.request({
				url: '/app/wechatApi/wechatOneFiveOrder/handleOrder',
				method: 'POST',
				data: values,
				header: {
					'Content-type': 'application/x-www-form-urlencoded'
				},
				success: res => {
					uni.hideLoading();
					if (res.data.code === 200) {
						uni.showToast({
							title: '操作成功!',
							icon: 'none'
						});
						setTimeout(function() {
							uni.navigateBack({
								delta: 2
							});
						}, 1500);
					} else {
						uni.showToast({
							title: res.data.message,
							icon: 'none'
						});
					}
				},
				error: e => {
					console.log(e);
				}
			});
		}
	}
};
</script>

<style lang="less">
.nav-chuli {
	padding:1upx;

	.uni-flex {
		box-shadow: 0px 0px 4px 4px rgba(0, 1, 2, 0.08);
		margin: 25upx;
		padding: 25upx;
		border-radius: 15upx;
		white-space: nowrap;
		
		input {
			width: 70%;
			color: #666;
			font-size: 30upx;
		}
		image {
			width: 230upx;
			height: 230upx;
			margin-top: 25upx;
		}

		.uni-set {
			width: 70%;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.uni-picker {
				width: 90%;
				padding-left: 15upx;
			}
			image {
				width: 20upx;
				height: 25upx;
				margin-top: -3upx;
			}
		}
	}
}
// 提交
.submit {
	background: #48E6E7;
	color: #ffffff;
	text-align: center;
	padding: 10upx 0;
	margin: 25upx;
	margin-top: 150upx;
	border-radius: 25upx;
}
</style>
